package com.yu.loadBalance;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @PackageName: com.yu.loadBalance
 * @Description:
 * @Version: v1.0.0
 * @Author: yuweilin
 * @Date: 10:48
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2021/2/6      yuweilin         v1.0.0               新建
 */
@Slf4j
public abstract class AbstractLoadBalance implements LoadBalance{
    @Override
    public String selectServiceAddress(List<String> serviceAddresses) {
        if (serviceAddresses.size()==1){
            return serviceAddresses.get(0);
        }
        log.info("发现服务存在多个地址，使用随机匹配策略降低负载");
        return doSelect(serviceAddresses);
    }
    protected abstract String doSelect(List<String> serviceAddresses);
}
